import logging
import random
import time

import pyautogui as pag

import pydirectinput as pdg


def click():
    pdg.mouseDown()
    pdg.mouseUp()


def double_click():
    pdg.mouseDown()
    pdg.mouseUp()
    pdg.mouseDown()
    pdg.mouseUp()


def get_and_click(image, use_double_click=False):
    target_pos = pag.locateOnScreen(image)
    goto_pos = pag.center(target_pos)

    pag.moveTo(goto_pos, duration=1)
    # pydirectinput.click()
    if not use_double_click:
        click()
    else:
        print("双击：", image)
        double_click()


def count_time(count=5):
    for i in reversed(list(range(count))):
        print(f"时间：{i}")
        time.sleep(1)


def click_start(image):
    # pag.doubleClick()
    target_pos = pag.locateOnScreen(image)
    goto_pos = pag.center(target_pos)
    pag.moveTo(goto_pos, duration=1)
    pag.click()
    # pag是不起作用的，就是控制是到图标这么细枝末节的东西（所有直属资源）
    pdg.press("enter")


def input_acc_info():
    pass


if __name__ == "__main__":
    start_btn = "images/start_game/start_game.png"
    logo = "images/start_game/logo.png"
    conform_contract = "images/start_game/confirm.png"
    agree_contract = "images/start_game/agree.png"
    # # get_and_click(logo, use_double_click=True)
    # click_start(logo)
    # count_time()
    # # 开始
    # get_and_click(start_btn)
    # count_time(count=10)
    # 点击协议
    pag.moveTo(200,200)
    pag.click()
    get_and_click(conform_contract)
    time.sleep(1)
    get_and_click(agree_contract)
